<script>
var state=<?php echo $this->state?>

$(document).ready(function() {
	if(state==1)
	{
		$( "#create_password" ).hide();
		$( "#link_user" ).dialog();
	}
	else{
		$( "#link_user" ).hide();
		$( "#create_password" ).dialog();
		}
	
	

	
	$("#signinbutton").click(function () {
		
		var email = $("#email").val();
		var password = $("#password").val();
		var rememberMe = $("input[id=remember_me]:checked").length;
		
		$.ajax({
		    type: 'POST',
		    url: context+'home/signin',
		    dataType: 'json',
		    async: false,
		    data:{'email':email,'password':password,'remember_me':rememberMe},
		    success: function(data){
			 
			    if(data['success'])
			    {
			    	$(location).attr('href',context+'queue');
			    }
			    else{
			    	 $("#error_authenticate span").html(data['error']);
				 }
		    },
		    error: function(xhr, status, thrown){
		    	
		    	 $("#error_authenticate span").html(xhr.responseText);
		    }
		});
		return false;
	});

$("#loginfacebookbutton").click(function () {
		$.ajax({
		    type: 'POST',
		    url: context+'home/fblogin',
		    dataType: 'json',
		    async: false,
		    success: function(data){
			   if(data['success'])
			    {
				   if(data['url'])
				   {
			    	$(location).attr('href',data['url']);
				   }
				   else{
					   $(location).attr('href',context+'queue');
					   }
			    }
			    else{
			    	 $("#error_authenticate span").html(data['error']);
				 }
		    },
		    error: function(xhr, status, thrown){
		    	 $("#error_authenticate span").html(xhr.responseText);
		    }
		});
		return false;
	});
});


</script>
 <?php
    $user = $this->identity();
   ?>
<div class="hero-unit">

<div id="create_password">
Create password
  <div>
     Email
      <input id="email" type="text" value="<?php echo $user->email?>" />
  </div>
  <div>
     Password
      <input id="password" type="password" value="armando" />
  </div>
   <div>
     Confirm Password
      <input id="confirm_password" type="password" value="armando" />
  </div>
    <button id="savebutton">Save</button>
</div>


<div id="link_user">
Link to your existing user account
  <div>
     Email
      <input id="email" type="text" value="<?php echo $user->email?>" />
  </div>
  <div>
     Enter your Password
      <input id="password" type="password" value="armando" />
  </div>
    <button id="linkbutton">Link</button>
</div>

 </div>


